/*
 * TarefaDao.java
 *
 * Created on 15 de Novembro de 2007, 20:41
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package br.com.sgpa.persistencia;

import br.com.sgpa.dominio.Colaborador;
import br.com.sgpa.dominio.Projeto;
import br.com.sgpa.dominio.Tarefa;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 *
 * @author Leandro
 */
public class TarefaDao extends Dao<Tarefa,Long> {
    
    /** Creates a new instance of TarefaDao */
    public TarefaDao(EntityManager em,Class classe) {
        super(em,classe);
    }
    
    public List<Tarefa> listarTarefasAExecutar(Colaborador col) {
        try {
            Query q = super.gerenciadorDeEntidades.createQuery("SELECT t FROM Tarefa t WHERE t.executor = ?1 AND t.ativa=true AND t.progressoPercente <> 100 ORDER BY t.dataCriacao DESC");
            q.setParameter(1, col );
            return q.getResultList();
        } catch (Exception ex)  {
            return null;
        }
    }
    
    
    public List<Tarefa> listarTarefas(Projeto proj) {
        try {
            Query q = super.gerenciadorDeEntidades.createQuery("SELECT t FROM Tarefa t WHERE t.projeto = ?1 AND t.ativa=true ORDER BY t.dataCriacao DESC");
            q.setParameter(1, proj );
            return q.getResultList();
        } catch (Exception ex)  {
            ex.getMessage();
            return null;
        }
    }
    
    
}
